package easybooking.clients;

import easybooking.FlightManagement;
import easybooking.data.*;
import easybooking.report.*;
import java.net.MalformedURLException;
import java.rmi.*;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.3308E1B7-217C-53CF-8719-E2B2B375BF5A]
// </editor-fold> 
public class ReportClient {

    public static void main(String[] args) {
        try {
            String rmiRegistryServer = System.getProperty("java.rmi.registry.hostname", "localhost");
            FlightManagement management = (FlightManagement) Naming.lookup("rmi://" + rmiRegistryServer + ":1099/FlightManagement1");

            System.out.println("Verbindung hergestellt...");

            ReportGenerator gen = management.getReportGenerator();
            Customer c = management.getCustomerByKey(6);
            Flight f = management.findFlightByKey(1);

            /*if (c != null) {
                AllFlightsOfCustomerReport report = gen.createAllFlightsOfCustomerReport(c);

                PlainTextReportWriter textWriter = new PlainTextReportWriter();
                textWriter.process(report);
                System.out.println(textWriter.getReportText());

                HTMLReportWriter htmlWriter = new HTMLReportWriter();
                htmlWriter.process(report);
                System.out.println(htmlWriter.getReportText());
            }*/
            if (f != null) {
                FlightSeatingReport report = gen.createFlightSeatingReport(f);

                PlainTextReportWriter textWriter = new PlainTextReportWriter();
                textWriter.process(report);
                System.out.println(textWriter.getReportText());

                HTMLReportWriter htmlWriter = new HTMLReportWriter();
                htmlWriter.process(report);
                System.out.println(htmlWriter.getReportText());
            }
        } catch (MalformedURLException murle) {
            System.out.println("MalformedURLException");
            System.out.println(murle);
        } catch (RemoteException re) {
            System.out.println("RemoteException");
            System.out.println(re);
        } catch (NotBoundException e) {
            System.out.println("NotBoundException");
            System.out.println(e);
        }
    }
}